package cn.kgc.service.impl;

import cn.kgc.pojo.EvaluateDetail;
import cn.kgc.mapper.EvaluateDetailMapper;
import cn.kgc.pojo.MalfunctionOptions;
import cn.kgc.service.EvaluateDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 评估信息详情 服务实现类
 * </p>
 *
 * @author qf
 * @since 2021-08-04
 */
@Service
public class EvaluateDetailServiceImpl extends ServiceImpl<EvaluateDetailMapper, EvaluateDetail> implements EvaluateDetailService {

    @Override
    public void saveBatchByOptions(Long id, List<MalfunctionOptions> optionList) {
        // 1.optionList进行遍历，获取单个option(故障详情)对象
        for (MalfunctionOptions option : optionList) {

            EvaluateDetail detail = new EvaluateDetail();
            detail.setEvaluateId(id);
            detail.setMalfId(option.getMalfId());
            detail.setOptionId(option.getId());
            detail.setOptionName(option.getOptionName());

            // 如果输入输出两个对象的属性名一样，可以使用beanUtil
            //BeanUtils.copyProperties(option, detail);

            // 执行保存
            this.save(detail);
        }
    }
}
